Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[read-fonts] revert midpoint change to match FT #1294

Merged
merged 1 commit into from
Dec 20, 2024
Merged

[read-fonts] revert midpoint change to match FT #1294

merged 1 commit into from
Dec 20, 2024

Conversation

dfrg
Copy link
Member

@dfrg dfrg commented Dec 20, 2024

A recent PR to fix an overflow changed the midpoint calculation from (a + b) / 2 to the "equivalent" a + (b - a) / 2 to attempt to avoid overflow with large values but this ends up producing results that don't exactly match FreeType in some cases.

This just changes the expression to a.wrapping_add(b) / 2 to restore compatibility while still avoiding the panic on overflow.

A recent PR to fix an overflow changed the midpoint calculation from `(a + b) / 2` to the "equivalent" `a + (b - a) / 2` to attempt to avoid overflow with large values but this ends up producing results that don't exactly match FreeType in some cases.

This just changes the expression to `a.wrapping_add(b) / 2` to restore compatibility while still avoiding the panic on overflow.
Copy link
Contributor

@drott drott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change LGTM, but please modify commit message:

to the "equivalent" a + (b - a) / 2 to

Please explicitly point out why the formula change was not equivalent, instead of leaving that to the reader interpreting the quotes.

@dfrg
Copy link
Member Author

dfrg commented Dec 20, 2024

Will add:

"The results differ when a > b and the sum is not even. For example, when a = 7 and b = 4, the first expression is (7 + 4) / 2 which yields 5 (and matches FreeType) while the second is 7 + (4 - 7) / 2 which yields 6."

@dfrg dfrg merged commit a79f00b into main Dec 20, 2024
10 checks passed
@dfrg dfrg deleted the fix-midpoint branch December 20, 2024 15:18
@drott
Copy link
Contributor

drott commented Dec 20, 2024

A recent PR to fix an overflow ...

This was e7161e7 in 0.26.2 - which I was starting to roll in Chromium but eventually did not land yet. https://chromium-review.googlesource.com/c/chromium/src/+/6088164 - it would be good to have this fix in a release, together with the fix for #1295 - then we need to update the roll into Chromium. I hope I get to it before the branch point (even though I am OOO).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants